/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddVehicle.java
 *
 * Created on Aug 3, 2011, 1:11:53 PM
 */
package invento;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JTable;


/**
 *
 * @author Kristina
 */
public class AddVehicle extends javax.swing.JFrame {
    private Connection con;
    private Statement statement;
    public DbConnector dbConn = new DbConnector();
    private JTable tab;
    
    JFrame parent;
    /** Creates new form AddVehicle */
    public AddVehicle(JFrame parent, JTable table) {
        initComponents();
        this.parent = parent;
        tab = table;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        buttonCANCELvehicle = new javax.swing.JButton();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jComboBox3 = new javax.swing.JComboBox();
        jComboBox5 = new javax.swing.JComboBox();
        jTextField8 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField1 = new javax.swing.JTextField();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Add Vehicle");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invento/addvehicletitle.png"))); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(53, 16, -1, 29));

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 16));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invento/addd.png"))); // NOI18N
        jButton1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 500, 69, 69));

        buttonCANCELvehicle.setFont(new java.awt.Font("Tahoma", 0, 16));
        buttonCANCELvehicle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invento/cancel2.png"))); // NOI18N
        buttonCANCELvehicle.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        buttonCANCELvehicle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonCANCELvehicleMouseClicked(evt);
            }
        });
        getContentPane().add(buttonCANCELvehicle, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 500, 69, 69));
        getContentPane().add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 300, 153, -1));
        getContentPane().add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 340, 154, -1));
        getContentPane().add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 260, 153, -1));

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "V-8 CUMMINS/CADILLAC", "Option 2", "Option 3" }));
        getContentPane().add(jComboBox3, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 100, 153, -1));

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "V-150 COMMANDO", "Option 2", "Option 3" }));
        getContentPane().add(jComboBox5, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 140, 153, -1));
        getContentPane().add(jTextField8, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 380, 153, -1));

        jLabel8.setText("(dd-mmm-yy)");
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 320, 72, -1));

        jLabel2.setText("Type:");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 100, -1, 20));

        jLabel3.setText("Make:");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 140, -1, 20));

        jLabel4.setText("Engine No.:");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 180, -1, 20));

        jLabel5.setText("Chassis No.:");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 220, -1, 20));

        jLabel9.setText("Acquisition Cost:");
        getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 340, 80, 20));

        jLabel6.setText("Property No.:");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 260, -1, 20));

        jLabel10.setText("Cost of Repair:");
        getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 380, -1, 20));

        jLabel7.setText("Acquisition Date:");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 300, -1, 20));

        jLabel11.setText("Source:");
        getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 420, 60, 20));

        jLabel12.setText("Status: ");
        getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 71, -1, -1));
        getContentPane().add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 220, 153, -1));

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Serviceable(SVC)", "Unserviceable(UNS)", "Beyond Economic Repair" }));
        getContentPane().add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(101, 63, 153, 22));
        getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 180, 153, -1));

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Loan", "Organic" }));
        getContentPane().add(jComboBox2, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 420, -1, -1));

        jLabel13.setText("Plate No.");
        getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 460, -1, 20));
        getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 460, 150, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonCANCELvehicleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonCANCELvehicleMouseClicked
        // TODO add your handling code here:
        returntomain();
    }//GEN-LAST:event_buttonCANCELvehicleMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String Stat = "\""+jComboBox1.getSelectedItem()+"\", ";
 	String Type = "\""+jComboBox3.getSelectedItem()+"\", ";
 	String Make = "\""+jComboBox5.getSelectedItem()+"\", ";
        String EngNo = "\""+jTextField1.getText()+"\", ";
        String ChasNo = "\""+jTextField4.getText()+"\", ";
        String PropNo = "\""+jTextField5.getText()+"\", ";
 	String AcqDate = "\""+jTextField6.getText()+"\", ";
 	String AcqCost = "\""+ jTextField7.getText()+"\", ";
        String RepCost = "\""+jTextField8.getText()+"\", ";
        String Source = "\""+jComboBox2.getSelectedItem()+"\", ";
        String PlateNo = "\""+jTextField2.getText()+"\")";


        int intTemp = 0;

        dbConn.dbConnect();
        try {
            dbConn.addVehicleToDatabase(Stat, Type, Make, EngNo, ChasNo, PropNo, AcqDate, AcqCost, RepCost, Source, PlateNo);

        }
        catch(Exception e){
            e.printStackTrace();
        }
        dbConn.dbConnect();
        dbConn.displayVehicle(tab);
        returntomain();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    
    public void returntomain(){
    
        this.setVisible(false);
        this.dispose();
        parent.setEnabled(true);
        parent.requestFocus();
        
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCANCELvehicle;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    // End of variables declaration//GEN-END:variables
}
